import { createRouter, createWebHistory } from 'vue-router'
import App from '@/App.vue'
import SimpleCarousel from '@/views/kjs/SimpleCarousel.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'App',
      redirect: '/SimpleCarousel',
      children: [
        {
          path: '/SimpleCarousel',
          name: 'SimpleCarousel',
          component: SimpleCarousel,
        },
        {
          path: '/maiche',
          name: 'maiche',
          component: () => import('@/views/kjs/buy/maiche.vue'),
        },
        {
          path: '/maishang',
          name: 'maishang',
          component: () => import('@/views/kjs/buy/maishang.vue'),
        },
        {
          path: '/qiugou1',
          name: 'qiugou',
          component: () => import('@/views/kjs/buy/qiugou.vue'),
        },
        {
          path: '/test',
          name: 'test',
          component: () => import('@/views/test.vue'),
        },
        {
          path: '/test3',
          name: 'test3',
          component: () => import('@/views/test3.vue'),
        },
        {
          path: '/test2',
          name: 'test2',
          component: () => import('@/views/kjs/shouye/test2.vue'),
        },
        {
          path: '/xiangqing/:id',
          name: 'xiangqing',
          component: () => import('@/views/kjs/shouye/xiangqing.vue'),
          props: true,
        },
        {
          path: '/Shang/:equipmentId',
          name: 'Shang',
          component: () => import('@/views/kjs/shouye/Shang.vue'),
          props: true,
        },
        { 
          path: '/My',
          name: 'My',
          redirect: '/My/MyZhongXin',
          component: () => import('@/views/my/My.vue'),
          children: [
            {
              path: 'MyZhongXin',
              name: 'MyZhongXin',
              component: () => import('@/views/my/MyZhongXin.vue'),
            },
            {
              path: 'MyOrders',
              name: 'MyOrders',
              component: () => import('@/views/my/MyOrders.vue'),
            },
            {
              path: 'MyCollection',
              name: 'MyCollection',
              component: () => import('@/views/my/MyCollection.vue'),
            },
            {
              path: 'MyShangHu',
              name: 'MyShangHu',
              component: () => import('@/views/my/MyShangHu.vue'),
            },
            {
              path: 'MyShangPing',
              name: 'MyShangPing',
              component: () => import('@/views/my/MyShangPing.vue'),
            },
              {
              path: 'MyKan',
              name: 'MyKan',
              component: () => import('@/views/my/MyKan.vue'),
            },
            {
              path: 'MyWantBuy',
              name: 'MyWantBuy',
              component: () => import('@/views/my/MyWantBuy.vue'),
            },
            {
              path: 'MyPurchase',
              name: 'MyPurchase',
              component: () => import('@/views/my/MyPurchase.vue'),
            }
          ],
        }
      ],
    },
    {
      path: '/Login',
      name: 'Login',
      component: () => import('@/views/login.vue'),
    }
  ],
  //除了主组件滚动到顶部，其他组件滚动到上次的滚动位置
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
  // scrollBehavior() {
  //   return { top: 0 }
  // }
})


export default router
